<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class RenameWechatUserIdInOrdersTable extends Migration
{
    public function up()
    {
        Schema::table('orders', function (Blueprint $table) {
            // 先删除原有外键
            if (Schema::hasColumn('orders', 'wechat_user_id')) {
                $table->dropForeign(['wechat_user_id']);
                $table->renameColumn('wechat_user_id', 'wechat_service_account_user_id');
            }
        });
    }

    public function down()
    {
        Schema::table('orders', function (Blueprint $table) {
            if (Schema::hasColumn('orders', 'wechat_service_account_user_id')) {
                $table->renameColumn('wechat_service_account_user_id', 'wechat_user_id');
                // 如有需要可重新添加外键
                // $table->foreign('wechat_user_id')->references('id')->on('wechat_users');
            }
        });
    }
} 